
function fun(list, target){
  let low = 0
      heigh = list.length - 1
  let middle = Math.floor((low + heigh) / 2)

  console.log(low, middle, heigh);

  while(low <= heigh){
    if(list[middle] == target){
      return middle
    }else if(list[middle] <= target){
      console.log("小了");
      low = middle + 1
      middle = Math.floor((low + heigh) / 2)
    }else{
      console.log("大了");
      heigh = middle - 1
      middle = Math.floor((low + heigh) / 2)
    }
    console.log(low, middle, heigh);
  }
  return null    
}


let list = [2,4,6,7,8]

// let result = fun(list, 4)
let result = fun(list, 9)
console.log("result ==> ", result);